package com.atme.micromall.points.controller;


import com.atme.micromall.points.dto.CommonResult;
import com.atme.micromall.points.service.PointsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/points")
@Api(tags = "积分服务")
public class PointsController {

    @Autowired
    private PointsService pointsService;

    /**
     * 创建积分
     * @param id  会员id
     * @return
     */
    @ApiOperation("创建积分")
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public CommonResult create(@RequestParam(value = "id") Integer id){
        System.out.println("被调用");
        int count = pointsService.create(id);
        if (count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }


    /**
     * 增减积分
     * @param id 会员id
     * @param number
     * @return
     */
    @ApiOperation("增减积分")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public CommonResult update(@RequestParam("id") Integer id,
                               @RequestParam("number") Integer number){

        int count = pointsService.update(id,number);
        if (count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }


/*    *//**
     * 积分增减记录
     * @param id 积分id
     * @param number
     * @return
     *//*
    @ApiOperation("积分增减记录")
    @RequestMapping(value = "record",method = RequestMethod.POST)
    public CommonResult updateRecord(@RequestParam("id") Integer id,
                               @RequestParam("number") Integer number){

        return null;
    }*/

    /**
     * 积分余额查询
     * @param id
     * @return
     */
    @ApiOperation("积分余额查询")
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public CommonResult getList(@RequestParam("id") Long id){

        return null;
    }


}
